<%@page import="java.util.*"%>
<%@page import="Data.*"%>
<%@page import="java.text.*"%>
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%--
The taglib directive below imports the JSTL library. If you uncomment it,
you must also add the JSTL library to the project. The Add Library... action
on Libraries node in Projects view can be used to add the JSTL 1.1 library.
--%>
<%--
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 
--%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        
        <h1>Checkout Page</h1>
        <table border="0">
            <thead>
                <tr>
                    <th>Description</th>
                    <th>Price</th>
                    <th></th>
                </tr>
                
            </thead>
            <tbody>
            <tbody>
                <%
                NumberFormat form = NumberFormat.getCurrencyInstance();
                TransactionBO transaction = (TransactionBO)session.getAttribute("transaction");
                if(transaction.getTxLines().equals(new ArrayList())){
                    out.println("<tr>");
                    out.println("<td>");
                    out.println("Your Shopping Cart is empty");
                    out.println("</td>");
                    out.println("</tr>");
                }else{
                    List<TransactionLineBO> transactionLineList = transaction.getTxLines();
                    
                    for (int i = 0; i < transactionLineList.size(); i++) {
                        TransactionLineBO transactionLine = transactionLineList.get(i);
                        RevenueSourceBO revSource = transactionLine.getRevenueSource();
                        
                        out.println("<tr>");
                        out.println("<td>");
                        out.println(revSource.getDescription());
                        out.println("<input type=\"hidden\" name=\"id\" value=\"" + transactionLine.getId() + "\">");
                        out.println("</td>");
                        out.println("<td>");
                        out.println(form.format(transactionLine.getTotalPrice()));
                        out.println("</td>");
                        out.println("</tr>");
                        
                    }
                    //Empty Space before the totals
                    out.println("<tr>");
                    out.println("<td align=\"right\" colspan=\"2\">");
                    out.println("&nbsp;");
                    out.println("</td>");
                    out.println("<tr>");
                    //Display SubTotal in the Shopping Cart
                    out.println("<tr>");
                    out.println("<td align=\"right\" colspan=\"2\">");
                    out.println("Subtotal: " + form.format(transaction.getSubtotal()));
                    out.println("</td>");
                    out.println("<tr>");
                    //Display Tax in the Shopping Cart
                    out.println("<tr>");
                    out.println("<td align=\"right\" colspan=\"2\">");
                    out.println("Tax: " + form.format(transaction.getTax()));
                    out.println("</td>");
                    out.println("<tr>");
                    //Display Total in the Shopping Cart
                    out.println("<tr>");
                    out.println("<td align=\"right\" colspan=\"2\">");
                    out.println("Total: " + form.format(transaction.getTotal()));
                    out.println("</td>");
                    out.println("<tr>");
                }
                
                %>
                
            </tbody>
        </table>
        <form action="edu.byu.isys413.actions.CompleteOrder.action" method="POST">
            <input type="submit" value="CompleteOrder">
        </form>
        <%--
    This example uses JSTL, uncomment the taglib directive above.
    To test, display the page like this: index.jsp?sayHello=true&name=Murphy
    --%>
        <%--
    <c:if test="${param.sayHello}">
        <!-- Let's welcome the user ${param.name} -->
        Hello ${param.name}!
    </c:if>
    --%>
    
    </body>
</html>
